
import requests

from libs.Logger import log


class RequestUtil:

    def __init__(self):
        pass

    def request(self,url,method,headers=None,param=None,content_type=None):
        try:
            if method == 'get':
                result = requests.get(url=url,params=param,headers=headers).json()
                return result
            elif method == 'post':
                if content_type == 'application/json':
                    result = requests.post(url=url,json=param,headers=headers).json()
                    return  result
                else:
                    result = requests.post(url=url,data=param,headers=headers).json()
                    return result
            else:
                log.info('http method not allow')
        except Exception as e:
            print(f'http 请求报错{e}')
            log.info(f'http 请求错误{e}')


if __name__ == '__main__':
    token = '77227A523C55419C2B5C29317A5FB09A'
    req = RequestUtil()
    param = {"crypt": "Bzm59b/yr3z6JimLip/cBXw75G+DYce7/RKpbT3C3aj8rFRYY3C/IqxflXWpTmhSMgkl+12wt5R3BT6NdgTyjn1KkbqCOvTk+PPA8YlvmyRF80Ko3XGz1x74uyTAIeMLdVlX5u7GyTNcgSJdr7iEsmfM9aUwaNsE0ZzX+E3glWU1+JTO4IpQKz4UN77XW/zfrx6mwUDN6sGbnNXzzxqd/dYiS89YkeG4TClRcjM71325wKI9Urilycks7sLM8vRLmU8CHT3o8Yd4m/thzmGhpyj9gClTh2SNVdDXmNBX6UcsJvpu/ZKhViK2E96JiT94JPMXxNw665ZPXXV4uTjxzg=="}
    print(req.request(f'https://dianchacha-service.ulucu.com/report/share/info?token={token}','post',param=param))
